<?php
class AlipayControl extends Control{
	function __construct(){
		parent::__construct();
		$this->user_id=$_SESSION["user_info"]["user_id"];
		$this->store_id=isset($_SESSION["user_info"]["store_id"])?$_SESSION["user_info"]["store_id"]:0;
		$rs=modcall("member","get",array("user_id={$this->user_id}"));
		$this->assign("user_info",$rs);
	}
	//绑定支付宝
	function bindAlipay(){
		if(!$_POST){
		$rs=modcall("member_bcard","find",array(
			array(
				"condition"=>"user_id={$this->user_id} AND bank_id=999",
				"order"=>"add_time desc",
				"join"=>array("tcz_bank_info"=>array("bi","bank_id","id")),
				"fields"=>"mb.id,mb.bank_name,mb.bank_id,mb.card_user,mb.card_number,bi.en_name"

			)
		));
		$this->assign("banks",$rs);
		$this->assign("page_type","safe_center");
			$this->display("alipaybind.html");
		}else{
			$card_user = $_POST["card_user"];
			$card_number = $_POST["card_number"];
			$rs=modcall("member_bcard","add",array(
			array(
				"bank_id"=>999,///999为支付宝
				"bank_name"=>"支付宝",
				"user_id"=>$this->user_id,
				"card_user"=>$card_user,
				"card_number"=>$card_number,
				"add_time"=>time()
			)
			));
			if(!$rs) $this->our_error("bind_faild");
			$this->out_result("success");
		}
	    
	}

	//接触绑定
	function delete(){
		$id=isset($_POST["id"])?intval($_POST["id"]):0;
		if(!$id) $this->out_error("no_id");
		$rs=modcall("member_bcard","delete",array("user_id={$this->user_id} and id={$id}"));
		if(!$rs) $this->out_error("delete_faild");
		$this->out_result("success");

	}
	
}
